package com.pifuke.patient;

import java.util.ArrayList;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;

import com.evan.common.pullrefresh.PullToRefreshBase;
import com.evan.common.pullrefresh.PullToRefreshBase.OnRefreshListener;
import com.pifuke.adapter.TreatmentProjectListAdapter;
import com.smiier.skin.TreatmentDetailActivity;
import com.smiier.skin.extra.TreatmentProjectItemExtra;
import com.smiier.skin.net.DoctorTreatmentProjectListTask.DoctorTreatmentProjectItem;
import com.smiier.skin.ui.BasicActivity;
import com.smiier.skin.util.GlobalSettings;
import com.umeng.analytics.MobclickAgent;

public class KepuXiangguanzhiliaoActivity extends BasicActivity implements
		OnRefreshListener<ListView>, OnItemClickListener {

	private ArrayList<DoctorTreatmentProjectItem> myData;

	// private PullToRefreshListView list_more_zhiliao;

	private ListView list_more_zhiliao;

	private TextView zhiliao_title;

	private TreatmentProjectListAdapter mTreatmentAdapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.activity_xiangguan_zhiliao_view);

		list_more_zhiliao = findViewById(R.id.list_more_zhiliao, ListView.class);

		zhiliao_title = findViewById(R.id.zhiliao_title, TextView.class);

		Bundle bundle = new Bundle();
		bundle = getIntent().getExtras();
		if (bundle != null && !bundle.isEmpty()) {
			myData = (ArrayList<DoctorTreatmentProjectItem>) bundle
					.getSerializable("data");

		}

		init();

		setNavTitle("治疗相关");

		zhiliao_title.setText("以下是有关 \" "
				+ GlobalSettings.symptomItemInfo.Patient_Name + "\"的治疗项目");

	}

	@Override
	protected void onStart() {
		super.onStart();

		mTreatmentAdapter = new TreatmentProjectListAdapter();
		mTreatmentAdapter.setShowDivider(false);
		// list_more_zhiliao.setOnRefreshListener(this);
		// list_more_zhiliao.doPullRefreshing(true);
		list_more_zhiliao.setOnItemClickListener(this);

		/*
		 * list_more_zhiliao.pullHeaderLayout(180);
		 * list_more_zhiliao.doPullRefreshing(true);
		 */

		list_more_zhiliao.setAdapter(mTreatmentAdapter);
		mTreatmentAdapter.setDataProvider(myData);
		mTreatmentAdapter.notifyDataSetChanged();

	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		DoctorTreatmentProjectItem item = (DoctorTreatmentProjectItem) mTreatmentAdapter
				.getDataProvider().get((int) id);
		Intent i = new Intent(getContext(), TreatmentDetailActivity.class);
		TreatmentProjectItemExtra extra = new TreatmentProjectItemExtra();
		extra.setUser(item);
		if (extra.putTo(i)) {
			startActivity(i);
		}

	}

	@Override
	public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onPullUpToLoadMore(PullToRefreshBase<ListView> refreshView) {
		// TODO Auto-generated method stub
	}
	
	
/*	@Override
	protected void onResume() {
		super.onResume();
		MobclickAgent.onResume(this);
	}

	@Override
	protected void onPause() {
		super.onPause();
		
		MobclickAgent.onPause(this);
	}
*/
}
